package com.project.visuallinks.server;

import com.project.visuallinks.client.sourceCodeService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import java.io.InputStream;
import java.net.*;

public class sourceCodeServiceImpl extends RemoteServiceServlet implements
		sourceCodeService {
	
	String responseJson = new String();

	public String getTop10Tags(String Url) {
		try {
			//create new URL connection to the request
			URL urlConnection = new URL(Url);
			//open the connection
			urlConnection.openConnection();
			//define an input stream to read the contents of the connection
			InputStream in = urlConnection.openStream();
			byte b[] = new byte[1000];
			int numRead = in.read(b);
			String content = new String(b, 0, numRead);
			while (numRead != -1) {

			    numRead = in.read(b);
			    if (numRead != -1) {
				String newContent = new String(b, 0, numRead);
				content += newContent;
			    }
			}
			in.close();
			responseJson = content;
			
		} catch (MalformedURLException e) {
			e.printStackTrace();
			
		} catch (Throwable e) {
			e.printStackTrace();
		}
		return responseJson;
	}
	
	
	
	public String getRelatedTags(String Url) {
		try {
			//create new URL connection to the request
			URL urlConnection = new URL(Url);
			//open the connection
			urlConnection.openConnection();
			//define an input stream to read the contents of the connection
			InputStream in = urlConnection.openStream();
			byte b[] = new byte[1000];
			int numRead = in.read(b);
			String content = new String(b, 0, numRead);
			while (numRead != -1) {

			    numRead = in.read(b);
			    if (numRead != -1) {
				String newContent = new String(b, 0, numRead);
				content += newContent;
			    }
			}
			in.close();
			responseJson = content;
			
		} catch (MalformedURLException e) {
			e.printStackTrace();
			
		} catch (Throwable e) {
			e.printStackTrace();
		}
		return responseJson;
	}
	
	
	
	public String getBookmarks(String Url) {
		try {
			//create new URL connection to the request
			URL urlConnection = new URL(Url);
			//open the connection
			urlConnection.openConnection();
			//define an input stream to read the contents of the connection
			InputStream in = urlConnection.openStream();
			byte b[] = new byte[1000];
			int numRead = in.read(b);
			String content = new String(b, 0, numRead);
			while (numRead != -1) {

			    numRead = in.read(b);
			    if (numRead != -1) {
				String newContent = new String(b, 0, numRead);
				content += newContent;
			    }
			}
			in.close();
			responseJson = content;
			
		} catch (MalformedURLException e) {
			e.printStackTrace();
			
		} catch (Throwable e) {
			e.printStackTrace();
		}
		return responseJson;
	}

}
